package com.changcheng.controller;
import com.changcheng.service.FileService;
import com.changcheng.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
@RestController
@Api(tags = "图片上传接口")
@RequestMapping("/oss/file")
public class OssTestController {
@Autowired
private FileService fileService;
    //上传文件到阿里云oss
    @ApiOperation(value = "文件上传")
    @PostMapping("fileUpload")
    public R fileUpload(MultipartFile file) {
        //获取上传文件
        if (file.getSize() > 1024 * 1024 * 10) {
            return R.error("图片太大");
        } else {
            String url = fileService.upload(file);

            return R.ok(url);
        }
    }
}
